package cn.daniel.commonutils;


import cn.daniel.commonutils.result.ResultCode;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;


import java.util.HashMap;
import java.util.Map;
@Data
//统一结果返回结果信息
public class Response {
    @ApiModelProperty(value = "是否成功")
    private  Boolean success;
    @ApiModelProperty(value = "返回码")
    private  Integer code;
    @ApiModelProperty(value = "返回信息")
    private  String message;
    @ApiModelProperty(value = "返回数据")
    private  Map<String,Object> data=new HashMap<>();

    //私有化构造器
    private Response(){};

    //运用静态的方法让外部获取该对象
    public static Response ok(){
        Response response = new Response();
        response.setSuccess(true);
        response.setCode(ResultCode.SUCCESS.getCode());
        response.setMessage(ResultCode.SUCCESS.getMessage());
        return response;
    }
    public static Response error(){
        Response response = new Response();
        response.setSuccess(false);
        response.setCode(ResultCode.ERROR.getCode());
        response.setMessage(ResultCode.ERROR.getMessage());
        return response;
    }
    public Response success(Boolean success){
        this.setSuccess(success);
        return this;
    }
    public Response code(Integer code){
        this.setCode(code);
        return this;
    }
    public Response message(String message){
        this.setMessage(message);
        return this;
    }
    public Response data(HashMap<String,Object> map){
        this.setData(map);
        return this;
    }
    public Response data(String key,Object value){
        this.data.put(key, value);
        return this;
    }


}
